/**
 * @file workspace_parser.h
 * @brief Code::Blocks workspace file parser and comment generator
 * @author AI Assistant
 * @date 2025-10-13
 * @version 1.0
 */

#ifndef WORKSPACE_PARSER_H
#define WORKSPACE_PARSER_H

#include <wx/wx.h>
#include <wx/xml/xml.h>
#include <vector>
#include <map>

class WorkspaceParser {
public:
    struct WorkspaceProject {
        wxString filename;
        wxString title;
        wxString path;
        bool active;
        
        WorkspaceProject() : active(false) {}
    };

    struct WorkspaceStats {
        int totalProjects;
        int totalFiles;
        int totalFunctions;
        double processingTime;
    };

    WorkspaceParser();
    virtual ~WorkspaceParser();

    // 主要接口函数
    bool ParseWorkspace(const wxString& workspaceFile);
    bool GenerateWorkspaceComments(bool silent = false);
    bool ProcessAllProjects(bool silent = false);
    
    // 获取信息
    wxString GetWorkspaceTitle() const { return m_workspaceTitle; }
    wxString GetWorkspaceFile() const { return m_workspaceFile; }
    WorkspaceStats GetStatistics() const { return m_stats; }
    std::vector<WorkspaceProject> GetProjects() const { return m_projects; }
    
    // 工具函数
    static bool IsWorkspaceFile(const wxString& filename);
    wxString GenerateWorkspaceHeader() const;
    
private:
    bool ParseWorkspaceXML();
    bool ExecuteCBPProcessor(const wxString& cbpFile, bool silent = false);
    void UpdateStatistics();
    wxString ExtractProjectTitle(const wxString& cbpFile);

    wxString m_workspaceFile;
    wxString m_workspaceTitle;
    wxString m_workspacePath;
    std::vector<WorkspaceProject> m_projects;
    WorkspaceStats m_stats;
    wxXmlDocument m_xmlDoc;
};

#endif // WORKSPACE_PARSER_H
